package com.api.user.controller;
import com.api.core.controller.Ctrl;
import com.api.core.response.Result;
import com.api.core.response.ResultGenerator;
import com.api.user.model.GameProfile;
import com.api.user.service.GameProfileService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.util.List;
import com.api.core.annotation.PowerEnable;
import io.swagger.annotations.*;


/**
* Created by wanghuiwen on 2021/03/23.
*/
@PowerEnable(name = "GameProfile",url = "/game/profile")
@Api(value = "GameProfile", tags = {"GameProfile"})
@RestController
@RequestMapping("/game/profile")
public class GameProfileController extends Ctrl{
    @Resource
    private GameProfileService gameProfileService;

    @ApiOperation(value = "GameProfile添加", tags = {"GameProfile"}, notes = "GameProfile添加")
    @PostMapping(value="/save",name="GameProfile添加")
    public Result add(@ApiParam GameProfile gameProfile,Authentication authentication) {

        Long userId = getAuthUser(authentication).getId();
        gameProfile.setUserId(userId);

        return gameProfileService.add(gameProfile);
    }


    

    @PostMapping(value = "/user", name = "GameProfile列表信息")
    public Result user(
            @RequestParam(required = false)Long userId,
            @RequestParam(defaultValue = "{}") String search,
                   @RequestParam(defaultValue = "{}") String order,
                   @RequestParam(defaultValue = "0") Integer page,
                       @RequestParam(defaultValue = "10") Integer size, Authentication authentication) {

        if(userId ==null){
            userId = getAuthUser(authentication).getId();
        }
        return gameProfileService.listByUser(search, order, page, size,userId);
    }


    @ApiOperation(value = "GameProfile添加", tags = {"GameProfile"}, notes = "GameProfile添加")
    @PostMapping(value="/delete",name="GameProfile删除")
    public Result delete(Long id) {
        gameProfileService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }
}
